﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace PleaseORM.Configuration
{
	internal class DatabaseConfiguration
	{
		public DatabaseConfiguration(string connectionString)
		{
			Connection = new SqlConnection(connectionString);
		}

		protected DbConnection OpenConnection()
		{
			if (Connection.State == ConnectionState.Closed)
				Connection.Open();

			return Connection;
		}

		internal void ExecuteCommand(string command)
		{
			var dbCommand = new SqlCommand(command, (SqlConnection)OpenConnection());
			dbCommand.ExecuteNonQuery();
		}

		internal DbDataReader ExecuteReader(DbCommand command)
		{
			command.Connection = OpenConnection();
			return command.ExecuteReader();
		}

		protected DbConnection Connection { get; set; }
		protected DbCommand Command { get; set; }
	}
}
